package org.example.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.example.entity.User;
import org.springframework.stereotype.Repository;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author 李云龙
 * @program: shiro_login
 * @description: usermapper
 * @date 2024-10-09 21:52:58
 */

@Repository
public interface UserMapper extends BaseMapper<User> {

    @Select("select r.CODE from role r\n" +
            "inner join user_role ur\n" +
            "on r.id = ur.rid\n" +
            "inner join user u\n" +
            "on ur.uid = u.id\n" +
            "and u.name=#{principal}")
    List<String> getUserRoleInfoMapper(@Param("principal") String principal);

    @Select("select p.code from permission p\n" +
            "inner join role_permission rp\n" +
            "on p.id = rp.pid\n" +
            "inner join role r \n" +
            "on rp.rid = r.id\n" +
            "inner join user_role ur\n" +
            "on r.id = ur.rid\n" +
            "inner join user u\n" +
            "on ur.uid = u.id\n" +
            "and u.name = #{principal}")
    List<String> getUserPermissionInfoMapperByPrincipal(@Param("principal") String principal);


    @Select("<script>" +
            "select p.code from permission p\n" +
            "inner join role_permission rp\n" +
            "on p.id = rp.pid\n" +
            "inner join role r \n" +
            "on rp.rid = r.id\n" +
            "and r.code in " +
            "<foreach collection='roles' item='name' open='(' separator=',' close=')'>" +
            "#{name}" +
            "</foreach>" +
            "</script>")
    List<String> getUserPermissionInfoMapperByRoles(@Param("roles") List<String> roles);



}
